<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
        rel="stylesheet" />
    <script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
    <style>
        body,
        html {
            height: 100%;
            box-sizing: border-box;
            background: #fff;
        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card layui-form">
            <div class="layui-form-item" style="padding-left:15px;">
                <label>退款编号</label>
                <div class="layui-inline" style="width:200px;">
                    <input type="text" class="layui-input" style="width:200px;" name="RefundNo" autocomplete="off"
                        placeholder="请输入退款单号" />
                </div>
                <label>退款状态</label>
                <div class="layui-inline" style="width:120px;">
                    <select name="RefundStatus">
                    </select>
                </div>
                <label>退款日期</label>
                <div class="layui-inline" style="width:200px;">
                    <input type="text" readonly="readonly" name="RefundDate" class="layui-input" id="RefundDate"
                        style="width:200px;" />
                </div>
                <div class="layui-inline" style="width:120px;">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-list-submit"
                        id="btnSearch">
                        <i class="layui-icon layuiadmin-button-btn layui-icon-search"></i>查询
                    </button>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="dataTable" lay-filter="dataTable"></table>
            </div>
        </div>
    </div>
    <script type="text/html" id="edit">
        {{# if(d.RefundStatus==0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="audit"><i class="layui-icon  layui-icon-edit"></i>审核</a>
        {{# } }}
        {{# if(d.RefundStatus==2){ }}
        <a class="layui-btn layui-btn-xs" lay-event="confirmgetgoods"><i class="layui-icon  layui-icon-edit"></i>确认收货</a>
        {{# } }}
        <a class="layui-btn layui-btn-xs" lay-event="detail"><i class="layui-icon  layui-icon-edit"></i>查看详情</a>
    </script>
    <script>
        layui.config({
            base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        });
        layui.define(["index", "form", "table", "jquery", "layer", "tree", "element", "upload", 'laydate'], function (exports) {
            var table = layui.table;
            var layer = layui.layer;
            var admin = layui.admin;
            var $ = layui.$;
            var tree = layui.tree;
            var form = layui.form;
            var laydate = layui.laydate;
            var oper = {
                data: {
                    sellistinfo: {},//选中列表行 
                    table: null,
                    tabledata: [],
                    listmodel: {},//列表行模型
                    refundstatus: [],
                    //退款状态 0退款中 1审核通过 2确认寄回 3确认收货  4退款成功 99审核拒绝
                    refundtype: [],//退款类型 1退款 2退货退款 3全部退款
                },
                init: function () {
                    var self = this;

                    Promise.all([self.GetDict(8147), self.GetDict(8148)]).then(res => {
                        self.data.refundstatus = res[0].data.appbasedict;
                        self.data.refundtype = res[1].data.appbasedict;
                        self.initSelect(self.data.refundstatus, "RefundStatus");
                        form.render("select");
                        self.tableLoad();
                    })
                    laydate.render({
                        elem: '#RefundDate'
                        , range: true //或 range: '~' 来自定义分割字符 
                        , max: this.formatDate(new Date())
                    });
                    self.initEvent();
                },
                formatDate(date) {
                    var y = date.getFullYear();
                    console.log(y);
                    var m = date.getMonth() + 1;
                    m = m < 10 ? '0' + m : m;
                    var d = date.getDate();
                    d = d < 10 ? ('0' + d) : d;
                    return y + '-' + m + '-' + d;
                },
                initSelect: function (data, name) {
                    var appendHtml = '';
                    appendHtml = "<option value='-1'>全部</option>";
                    data.forEach(a => {
                        appendHtml += "<option value=" + a.Code + ">" + a.Name + "</option>";
                    })
                    $("[name=" + name + "]").html(appendHtml);
                },
                //表数据加载
                tableLoad: function () {
                    var self = this;
                    var refundStatus = $("[name='RefundStatus']").val();
                    var refundNo = $("[name='RefundNo']").val();
                    var refundDate = $("[name='RefundDate']").val();
                    self.data.classTable = table.render({
                        elem: "#dataTable",
                        where: {
                            refundStatus: refundStatus,
                            refundNo: refundNo,
                            sdate: refundDate.split(' - ')[0],
                            edate: refundDate.split(' - ')[1],
                        },
                        url: self.getbaseurl("Mall.GetBackStageRefundList"),
                        height: "full-100",
                        size: '10',
                        page: true, //开启分页 
                        loading: true,
                        cols: [[
                            { field: 'RefundNo', title: '退款编号', width: '15%', fixed: 'left' },
                            { field: 'OrderNo', title: '订单编号', width: '15%', fixed: 'left' },
                            //{ field: 'TradeNo', title: '交易流水号', width: '15%' },
                            {
                                field: 'RefundType', title: '退款类型', width: '8%', templet: function (d) {
                                    var filter = self.data.refundtype.filter(a => { return a.Code == d.RefundType; });
                                    if (filter != null && filter.length > 0)
                                        return filter[0].Name;
                                    else
                                        return "";
                                }
                            },
                            {
                                field: 'RefundStatus', title: '退款状态', width: '8%', templet: function (d) {
                                    var filter = self.data.refundstatus.filter(a => { return a.Code == d.RefundStatus; });
                                    if (filter != null && filter.length > 0)
                                        return filter[0].Name;
                                    else
                                        return "";
                                }
                            },
                            { field: 'RefundFee', title: '退款金额', width: '10%' },
                            {
                                field: 'RefundDate', title: '退款时间', width: '15%', templet: function (d) {
                                    return (d.RefundDate || "").substring(0, 19);
                                }
                            },
                            {
                                field: 'SuccessTime', title: '成功时间', width: '15%', templet: function (d) {
                                    return (d.SuccessTime || "").substring(0, 19);
                                }
                            },
                            {
                                field: 'AuditTime', title: '审核时间', width: '15%', templet: function (d) {
                                    return (d.AuditTime || "").substring(0, 19);
                                }
                            },
                            {
                                field: 'AuditStatus', title: '审核结果', width: '15%', templet: function (d) {
                                    if (d.AuditStatus == 1)
                                        return "审核通过";
                                    else if (d.AuditStatus == 2)
                                        return "<span style='color: red;'>审核不通过</span>";
                                    else
                                        return "";
                                }
                            },
                            { field: 'operation', title: '操作', toolbar: '#edit', fixed: 'right', width: '20%' }
                        ]]
                        , done: function (res) {

                        }
                    });
                },
                //页面加载
                initEvent: function () {
                    var self = this;
                    //订单详情查看，发货
                    table.on('tool(dataTable)', function (obj) {
                        var data = obj.data;//当前行数据 
                        window.sellistinfo = data;
                        window.refundstatus = self.data.refundstatus;
                        window.refundtype = self.data.refundtype;
                        switch (obj.event) {
                            case 'audit':
                                self.openEdit("退款审核");
                                break;
                            case 'detail':
                                self.openDetail(data.RefundNo + '-详情');
                                break;
                            case 'confirmgetgoods':
                                layer.confirm('确认收货吗？', { icon: 3, title: '提示' }, function (index2) {
                                    layer.msg('正在收货，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });
                                    self.confirmgetgoods(data, () => {
                                        self.tableLoad();
                                        layer.close(index2);
                                    });
                                });
                                break;
                        }
                    });
                    //查询列表
                    form.on("submit(LAY-list-submit)", function (data) {
                        self.tableLoad();
                    });
                },
                //打开编辑器
                openEdit: function (title) {
                    var self = this;
                    layer.open({
                        type: 2
                        , title: title
                        , content: "edit.html"
                        , area: ['50%', '100%']
                        , btn: ['审核', '取消']
                        , resize: false
                        , success: function (layero, index) {

                        }
                        , btn2: function (index, layero) {

                        }
                        , cancel: function () {

                        }
                        , yes: function (index, layero) {
                            var a = getResult()
                            if (a.AuditMemo == "") {
                                layer.msg("审核备注不能为空");
                                return;
                            }
                            layer.confirm('确认审核吗？', { icon: 3, title: '提示' }, function (index2) {
                                if (a != null) {
                                    layer.msg('正在审核，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });
                                    self.audit(a, () => {
                                        self.tableLoad();
                                        layer.close(index2);
                                        layer.close(index);

                                    })
                                }
                            });
                        }
                    });
                },
                //打开编辑器
                openDetail: function (title) {
                    var self = this;
                    layer.open({
                        type: 2
                        , title: title
                        , content: "detail.html"
                        , area: ['50%', '100%']
                        , resize: false
                        , success: function (layero, index) {

                        }
                        , btn2: function (index, layero) {

                        }
                        , cancel: function () {

                        }
                        , yes: function (index, layero) {

                        }
                    });
                },
                //获取应用字典
                GetDict: function (classId) {
                    return new Promise((resolve, reject) => {
                        admin.req({
                            url: '/common/v1/BasicData/GetAppBaseDict',
                            method: "get",
                            data: {
                                classId: classId,
                                appKey: "APP20200616102057595"
                            },
                            done: res => {
                                resolve(res);
                            }
                        });
                    })
                },
                //审核
                audit: function (data, succ) {
                    var self = this;
                    admin.req({
                        url: self.getbaseurl("Mall.Audit"),
                        method: "post",
                        data: data,
                        done: res => {
                            layer.msg("审核成功!")
                            succ && succ();
                        }
                    });
                },
                //确认收货
                confirmgetgoods(data, succ) {
                    var self = this;
                    admin.req({
                        url: self.getbaseurl("Mall.ConfirmGetGoods"),
                        method: "post",
                        data: data,
                        done: res => {
                            if (res.code == 0) {
                                layer.msg("操作成功!")
                                succ && succ();
                            }
                            else
                                layer.msg("操作失败!")
                        }
                    });
                },
                getbaseurl: function (fun) {
                    var url = "/lowcode/APP20200616102057595/shop/?view=layui&fun=" + fun;
                    return url;
                },
            }
            oper.init()
        });
    </script>
</body>

</html>